/**
 * 事件，地图上添加一个基地中心点
 */
 var onAddBaseMarkerListeners = [];
 var onDrawBaseEndListeners = []; 
 var drawPartitionListeners = [];
 var drawFieldListeners = [];
 var drawRoomListeners = [];
 var drawFacilitiesListeners = [];
 var drawDeviceListeners = [];
 var saveFeatureOk = []; //保存成功
 /**
  * 注册事件
  */
 function on(type,listener){
    if(types.onAddBaseMarker == type){
        onAddBaseMarkerListeners.push(listener);
    }else if(types.onAddBase == type){
        onDrawBaseEndListeners.push(listener);
    }else if(types.onAddPartition == type){
        drawPartitionListeners.push(listener);
    }else if(types.onAddField == type){
        drawFieldListeners.push(listener);
    }else if(types.onSaveFeatureOk == type){
        saveFeatureOk.push(listener);
    }else if(types.onAddRoom == type){
        drawRoomListeners.push(listener);
    }else if(types.onAddFacilities == type){
        drawFacilitiesListeners.push(listener);
    }else if(types.onAddDevice == type){
        drawDeviceListeners.push(listener)
    }

 }

 /**
  * 触发事件
  */
 function fire(type,params){
     var targets = null;
    if(types.onAddBaseMarker == type){
        targets = onAddBaseMarkerListeners;
    }else if(types.onAddBase == type){
        targets =  onDrawBaseEndListeners;
    }else if(types.onAddPartition == type){
        targets =  drawPartitionListeners;
    }else if(types.onAddField == type){
        targets =  drawFieldListeners;
    }else if(types.onSaveFeatureOk == type){
        targets =  saveFeatureOk;
    }else if(types.onAddRoom == type){
        targets =  drawRoomListeners;
    }else if(types.onAddFacilities == type){
        targets = drawFacilitiesListeners;
    }else if(types.onAddDevice == type){
        targets = drawDeviceListeners;
    }

    for(var i=0; i< targets.length;i++){
        var l = targets[i];
        l(params); //开始调用事件监听者
    }
 }

 /**
  * 事件类型集合
  */
 const types = {
     onAddBaseMarker:'onAddBaseMarker', //添加基地中心点
     onAddBase:'onAddBase', //圈定基地
     onAddPartition:'onAddPartition', //添加分区
     onAddField:'onAddField', //添加地块
     onSaveFeatureOk:'onSaveFeatureOk', //保存地图上的地块成功
     onAddRoom:'onAddRoom', //添加房间
     onAddFacilities:'onAddFacilities' , //添加设施
     onAddDevice:'onAddDevice' //添加设备
 }

 export {fire,on,types}

